﻿@page "/dialogcard/{OrderID}"

@using NorthwindBlazor.Data
@using NorthwindBlazor.Models.Northwind
@using Microsoft.EntityFrameworkCore

@inject NorthwindContext dbContext
@inject DialogService dialogService

<h1 style="display:inline">Dialog with parameters</h1><a style="margin-left: 10px" href="https://github.com/akorchev/blazor.radzen.com/blob/master/Pages/DialogCardPage.razor" target="_blank">[source code]</a>

<p>This page demonstrates <b>Dialog</b> component with parameters.</p>
<h3>OrderID: @OrderID</h3>
<RadzenCard Style="margin-bottom: 20px;">
    <div class="row">
        <div class="col-md-6">
            <div>Company:</div>
            <b>@order.Customer?.CompanyName</b>
            <div style="margin-top:20px">Employee:</div>
            <b>@(order.Employee?.FirstName + " " + order.Employee?.LastName)</b>
            <br />
            <RadzenImage Path="@order.Employee?.Photo" Style="width:100px;" />
        </div>
        <div class="col-md-6">
            <div>Freight:</div>
            <b>@String.Format(new System.Globalization.CultureInfo("en-US"), "{0:C}", order.Freight)</b>
            <div style="margin-top:20px">Ship country:</div>
            <b>@(order.ShipCountry)</b>
            <div style="margin-top:20px">Ship city:</div>
            <b>@(order.ShipCity)</b>
            <div style="margin-top:20px">Ship name:</div>
            <b>@(order.ShipName)</b>
        </div>
    </div>
</RadzenCard>
<div class="row">
    <div class="col-md-12">
        <RadzenButton Click="@((args) => dialogService.Close(true))" Text="OK" Style="margin-bottom: 10px; width: 150px" />
        <RadzenButton Click="@((args) => dialogService.Close(false))" ButtonStyle="secondary" Text="Cancel" Style="margin-bottom: 10px; width: 150px" />
    </div>
</div>

@code {
    [Parameter] private int OrderID { get; set; }

    Order order;

    protected override async Task OnInitAsync()
    {
        await Invoke(() =>
        {
            var query = from order in dbContext.Orders.Where(o => o.OrderID == OrderID)
                           .Include("Customer")
                           .Include("Employee")
                           .Include("OrderDetails")
                           .Include("OrderDetails.Product")
                        select order;

            order = query.Last();

            StateHasChanged();
        });
    }
}
